package com.wiscamp.ninechapters.problems.infrastructure.mappers.sheets;

import com.wiscamp.ninechapters.problems.infrastructure.po.sheets.SheetDetailPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;

/**
 * 答题卡明细仓储对象
 *
 * @author yifeng
 */
@Repository
public interface SheetDetailMapper extends JpaRepository<SheetDetailPO, Long>, JpaSpecificationExecutor<SheetDetailPO> {

    //@Query(value = "select e from SheetDetailPO e where e.problemId = :problemId and e.questionId = :questionId")
    //SheetDetailPO findByProblemAndQuestion(long problemId, long questionId);

    @Query(value = "select e from SheetDetailPO e where e.sheetId = :sheetId")
    Collection<SheetDetailPO> findListBySheet(long sheetId);

    @Query(value = "select e from SheetDetailPO e, SheetPO s where e.sheetId = e.sheetId and s.taskId = :taskId and e.problemId = :problemId and e.questionId = :questionId")
    Collection<SheetDetailPO> findByTaskAndQuestion(long taskId, long problemId, long questionId);

    //@Query(value = "select e from SheetDetailPO e where e.sheetId in (:sheetIds)")
    //Collection<SheetDetailPO> findListBySheets(Collection<Long> sheetIds);

    //@Query(value = "select e from SheetDetailPO e where e.sheetId in (:sheetIds) and e.problemId = :problemId")
    //Collection<SheetDetailPO> findListBySheetsAndProblem(Collection<Long> sheetIds, long problemId);

    //@Query(value = "select e from SheetDetailPO e where e.sheetId in (:sheetIds) and e.problemId in (:problemId)")
    //Collection<SheetDetailPO> findListBySheetsAndProblems(Collection<Long> sheetIds, Collection<Long> problemId);
}